package com.itany.book.service.impl;

import com.github.pagehelper.util.StringUtil;
import com.itany.book.service.ManagerUserService;
import com.itany.exception.RequestParamException;
import com.itany.exception.UserNotExistException;
import com.itany.mapper.ManagerUserMapper;
import com.itany.pojo.ManagerUser;
import com.itany.utils.ParamUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

/**
 * Auther:ws@itany.com
 * Date:20-10-9 上午10:36
 * Version:1.0
 * Description:
 */
@Service
@Transactional(propagation = Propagation.SUPPORTS,rollbackFor = Exception.class)
public class ManagerUserServiceImpl implements ManagerUserService {
    @Autowired
    private ManagerUserMapper managerUserMapper;

    @Override
    public ManagerUser login(String username, String password) throws RequestParamException, UserNotExistException {
        if (ParamUtils.isNull(username) || ParamUtils.isNull(password)){
            throw new RequestParamException("请求参数错误");
        }
        ManagerUser loginUser = managerUserMapper.login(username, password);
        if (null == loginUser){
            throw new UserNotExistException("账户或密码错误");
        }
        return loginUser;
    }
}
